package net.huashitong.oversee.web;

import com.sirdc.modules.core.web.JsonBaseController;
import com.sirdc.modules.core.web.model.Message;
import com.sirdc.modules.sys.entity.SysFile;
import com.sirdc.modules.sys.entity.SysPicture;
import com.sirdc.modules.sys.service.SysPictureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller

public class PicUpLoadCtrl extends JsonBaseController {

    @Autowired
    private SysPictureService sysPictureService;

    @Override
    protected String getView(String s) {
        return null;
    }
    //文件上传
    @ResponseBody
    @RequestMapping("/uploadBatch")
    public Message uploadfile(@RequestParam MultipartFile[] files)
    {
        if (files == null || files.length==0) {
            return coverMessage("500", "上传文件为空");
        }
        List<Map<String, Object>> maps = new ArrayList<Map<String,Object>>();
        for (MultipartFile multipartFile : files) {
            SysPicture sysPicture = new SysPicture();
            try {
                sysPictureService.savePicture(sysPicture, multipartFile);
            } catch (Exception e) {
                e.printStackTrace();
            }
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("sysId", sysPicture.getSysId());
            maps.add(map);
        }

        return coverMessage("200", "上传文件成功", maps);

    }


    /*public String getFilePath (String fileid )
    {
       SysPicture pic =  sysPictureService.getById(fileid);
        if (pic == null) {

            throw new Exception(" current request path is empty");
        }
        String filepath  = getu

    }*/

}
